package nc.hw;

public class HJ35 {

    private static void outputSnakeMa(int num) {
        // 本质是将倒三角向右旋转45度
        int[][] nums = new int[num][];
        for (int i = 0; i < num; i++) {
            nums[i] = new int[num];
        }
        int c = 1;
        for (int i = 0; i < num; i++) {
            // 将i分解
            for (int j = 0; j <= i; j++) {
                int y = i - j;
                nums[y][j] = c;
                c ++;
            }
        }
        for (int i = 0; i < num; i++) {
            StringBuilder sb = new StringBuilder();
            sb.append(nums[i][0]);
            for (int j = 1; j < num; j++) {
                if (nums[i][j] != 0) {
                    sb.append(" ").append(nums[i][j]);
                }
            }
            System.out.println(sb);
        }
    }

    public static void main(String[] args) {
        outputSnakeMa(5);
    }

}
